package br.com.virtual.relatorio.dao.impl;

import java.util.Calendar;
import java.util.List;

import br.com.virtual.base.dao.impl.BaseDaoImpl;
import br.com.virtual.relatorio.dao.RelatorioDAO;
import br.com.virtual.vender.model.Venda;

public class RelatorioVendasDAOImpl extends BaseDaoImpl implements RelatorioDAO<Venda> {

	@Override
	public List<Venda> listByPeriod(Calendar start, Calendar end) {

		StringBuilder query = new StringBuilder();
		query.append("SELECT DISTINCT v FROM Venda v ");
		query.append(" INNER JOIN FETCH v.itens iv "); 
		query.append(" WHERE v.dataVenda BETWEEN :start AND :end");
		query.append(" order by v.dataVenda ");
		
		return getManager()
			.createQuery( query.toString(), Venda.class )
			.setParameter("start", start)
			.setParameter("end", end)
			.getResultList();
		
	}
}
